package leetcode;

import java.util.Arrays;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 2/24/2022 8:38 AM
 */
@Slf4j
public class Test455 {


    @Test
    public void test() {
        int[] arr1 = {1, 2, 3, 4};
        int[] arr2 = {1, 3, 3, 4, 5, 6};

        int contentChildren = findContentChildren(arr1, arr2);
        log.info(String.valueOf(contentChildren));
    }

    /**
     * @param g 每个孩子的需求量
     * @param s 饼干数
     * @return int
     */
    public int findContentChildren(int[] g, int[] s) {
        Arrays.sort(g);
        Arrays.sort(s);
        int m = g.length;
        int n = s.length;

        int count = 0;
        for (int i = 0, j = 0; i < m && j < n; i++, j++) {
            // 没有满足的情况
            while (j < n && g[i] > s[j]) {
                j++;
            }
            if (j < n) {
                count++;
            }
        }
        return count;
    }


}
